const express = require('express');
const app = express();

app.use((request, repsonse, next) => {
    console.log("有人请求服务2了");
    console.log("请求来自于: ", request.get("Host"));
    console.log("请求路径是：", request.url);
    console.log("请求方法：", request.method);
    next();
});

app.get("/cars", (request, response) => {
    const cars = [
        { id: 1, name: "奔驰", price: 199 },
        { id: 2, name: "宝马", price: 299 },
        { id: 3, name: "奥迪", price: 399 },
    ];
    response.send(cars);
})

app.listen(5002, (err) => {
    if (!err) console.log("服务器2启动成功了，请求地址为：http://localhost:5002/cars");
    else console.log(err);
})